package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.BookingOrderDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean2;
import com.itheima.pojo.BookingOrder;
import com.itheima.service.BookingOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author zero
 * @date 2020/6/5
 */

@Service(interfaceClass = BookingOrderService.class)
@Transactional
public class BookingOrderServiceImpl implements BookingOrderService {

    @Autowired
    private BookingOrderDao bookingOrderDao;

    @Override
    public PageResult pageQuery(QueryPageBean2 queryPageBean2) {
        //处理日期格式
        List<Date> dateRange = queryPageBean2.getDateRange();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String beginDate = sdf.format(dateRange.get(0));
        String endDate = sdf.format(dateRange.get(1));

        PageHelper.startPage(queryPageBean2.getCurrentPage(),queryPageBean2.getPageSize());
        Page<BookingOrder> bookingOrders = bookingOrderDao.selectByCondition(beginDate,endDate,queryPageBean2.getQueryString(),queryPageBean2.getAppointmentType(),queryPageBean2.getAppointmentStatus());
        long total = bookingOrders.getTotal();
        return new PageResult(total,bookingOrders.getResult());
    }
}
